`
https://leetcode.cn/problems/car-pooling/
`

/**
 * @param {number[][]} trips
 * @param {number} capacity
 * @return {boolean}
 */
var carPooling = function (trips, capacity) {
  const diff = new Array(1001).fill(0)

  for (const t of trips) {
    const num = t[0], i = t[1], j = t[2]
    diff[i] += num
    if (j <= 1001) {
      diff[j] -= num
    }
  }

  const res = new Array(1001).fill(0)
  res[0] = diff[0]
  if (res[0] > capacity) return false

  for (let i = 1; i < diff.length; i++) {
    const cur = diff[i] + res[i - 1]
    if (cur > capacity) {
      return false
    } else {
      res[i] = cur
    }
  }

  return true
};